<template>
  <d2-container>
    <div>
      <el-tabs type="border-card" @tab-click="handleClick" v-model="activeName">
        <el-tab-pane label="审批历史" name="first">
          <div>
            <el-table
              :data="tableData"
              border
              :cell-style="{ 'text-align': 'center' }"
              :header-cell-style="{ 'text-align': 'center' }"
            >
              <el-table-column label="序号" type="index" width="55">
              </el-table-column>
              <el-table-column prop="modified_time" label="日期" sortable>
                <template slot-scope="scope">{{
                  scope.row.modified_time | dateYMDHMSFormat_ss
                }}</template>
              </el-table-column>
              <el-table-column prop="process_step.name" label="审批阶段">
              </el-table-column>
              <el-table-column prop="creator.name" label="操作者">
              </el-table-column>
              <el-table-column prop="result" label="结果"> </el-table-column>
              <el-table-column prop="opinion" label="意见"> </el-table-column>
            </el-table>
            <!-- <el-pagination
              style="margin-top:10px"
              @current-change="handlePaginationChange"
              :current-page="formInline.p"
              :page-size="formInline.pageSize"
              layout="total, prev, pager, next"
              :total="formInline.count"
            >
            </el-pagination> -->
          </div>
        </el-tab-pane>
        <el-tab-pane label="审批流程" name="second">
          <el-steps :active="lenghtNum" align-center>
            <el-step
              v-for="item in shuju"
              :key="item.index"
              :title="item.name"
            ></el-step>
          </el-steps>
          <div class="boxs">
            <div v-for="items in shuju" :key="items.index" :class="{activess:items.index<=lenghtNum}">
              <div style="margin:10px 0px">
                <span>抄送人：</span>
                <span v-for="ist in items.send_user" :key="ist.id">
                  {{ist.name}}
                </span>
              </div>
              <div v-if="items.index!=1">
                <span>审批人：</span>
                <span v-for="ists in items.process_user" :key="ists.id">
                  {{ists.name}}
                </span>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </d2-container>
</template>
<script>
import api from "@/api";
import { getOrder_process_his, getWork_order } from "@/api/url";
export default {
  data() {
    return {
      tableData: [],
      id: this.$route.query.id,
      shuju: [],
      activeName: "first",
      formInline: {
        p: 1,
        pageSize: 20,
        count: 0,
        order_id: ""
      },
      lenghtNum:0
    };
  },
  created() {
    this.formInline.order_id = this.id;
    getOrder_process_his(this.formInline).then(res => {
      let indes = 1;
      res.result.results.forEach(item => {
        if (item.result == 0) {
          item.result = "发起";
        } else if (item.result == 1) {
          item.result = "同意";
        } else if (item.result == 2) {
          item.result = "驳回";
        } else if (item.result == 3) {
          item.result = "退审";
        } else if (item.result == -1) {
          item.result = "未处理";
        }
        var name = "";
        if (item.creator != null) {
          name = item.creator.name;
        }
        this.shuju.push({
          index: indes,
          resultss: item.result,
          process_user: item.process_step.process_user,
          send_user: item.process_step.send_user,
        });
        indes++;
      });
      this.formInline.count = res.result.count;
      this.tableData = res.result.results;
      for(var i =0;i<this.shuju.length;i++){
        if(this.shuju[i].resultss=='未处理'){
          this.lenghtNum=this.shuju[i].index-1
          return
        }
      }
      this.lenghtNum=this.shuju.length
    });
  },
  methods: {
    handleClick(tab, event) {
      // console.log(tab, event);
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    },
    // handlePaginationChange(val) {
    //   this.formInline.p = val;
    //   getOrder_process_his(this.formInline).then(res => {
    //     res.result.results.forEach(item => {
    //       if (item.result == 0) {
    //         item.result = "发起";
    //       } else if (item.result == 1) {
    //         item.result = "同意";
    //       } else if (item.result == 2) {
    //         item.result = "驳回";
    //       } else if (item.result == 3) {
    //         item.result = "退审";
    //       }
    //     });
    //     this.formInline.count = res.result.count;
    //     this.tableData = res.result.results;
    //   });
    // }
  }
};
</script>
<style scoped>
.boxs {
  width: 100%;
  display: flex;
  justify-content: space-around;
}
.activess {
  color: #409EFF;
}
</style>
